from MGFSever import predict
from flask import Flask, jsonify
from flask_restful import reqparse, Api, Resource

app = Flask(__name__)
api = Api(app)

class mgfForecast(Resource):
    def __init__(self):
        self.parser = reqparse.RequestParser()
        self.parser.add_argument("datalist", type=str, required=True, help="The historical data.")

    def get(self):
        args = self.parser.parse_args()
        data = args['datalist']
        data_list = [float(x) for x in data.split(",")]
        # print(data_list)
        ret = predict(data_list).tolist()
        print(ret)
        return jsonify(ret)



api.add_resource(mgfForecast, "/mgf")
if __name__ == "__main__":
    app.run(host='0.0.0.0', port='5337', threaded=False)

